import Vue from "vue"
import Vuex from "vuex"
import "whatwg-fetch"
import router from "./router"
import "@/service"
import "@/components"
import App from "./App.vue"
import store from "./store/index"
/* 投诉 TODO */
/* import getStore from "./store/index" */
import get from "lodash/get"
import busPlugin from "@/plugins/bus.js"
import "@/plugins/globalResize.js"
import "@/plugins/localStore.js";
import "./directive/index"
import "./filters"

import VueClipboard from 'vue-clipboard2'

Vue.prototype.$get = get

Vue.use(Vuex)
Vue.use(busPlugin)

Vue.use({
	install(Vue) {
		Vue.prototype.$log = console.log

		Vue.mixin({
			computed: {
			},
			methods: {
				$getSrDict(key, callback) {
					return this.$store.dispatch("dict/getDict", {
						key,
						callback: callback,
						moduleName: "sr"
					})
				},
				$getOutDict(key, callback) {
					return this.$store.dispatch("dict/getDict", {
						key,
						callback: callback,
						moduleName: "out"
					})
				},
				$getZskDic(key, callback, config = {}) {
					return this.$store.dispatch("dict/getDict", {
						key,
						callback: callback,
						moduleName: "zsk",
						...config
					})
				},
				$getCmgDict(key, callback) {
					return this.$store.dispatch("dict/getDict", {
						key,
						callback: callback,
						moduleName: "cmg"
					})
				},
				$getJsonDict(key, callback) {
					return this.$store.dispatch("dict/getDict", {
						key,
						callback: callback,
						moduleName: "json",
						dataFormatHandle: (data) => {
							const arr = ['-1', '', 'undefined']
							return data.filter(v => {
								return !arr.includes(v.value)
							})
						}
					})
				},
				$getAiqmDict(key, callback) {
					return this.$store.dispatch("dict/getDict", {
						key,
						callback: callback,
						moduleName: "aiqm"
					})
				},
				$getSamDict(key, callback) {
					return this.$store.dispatch("dict/getDict", {
						key,
						callback: callback,
						moduleName: "sam"
					})
				},
				$getNtDict(key, callback) {
					return this.$store.dispatch("dict/getDict", {
						key,
						callback: callback,
						moduleName: "nt"
					})
				}
			}
		})

		Vue.mixin({
			data() {
				return { onlyInitOnceMap_: {}}
			},
			methods: {
				$getOnceItem(key, handle) {
					if (!this.onlyInitOnceMap_) {
						this.onlyInitOnceMap_ = {}
					}
					if (this.onlyInitOnceMap_[key]) {
						return this.onlyInitOnceMap_[key]
					}

					this.onlyInitOnceMap_[key] = handle()

					return this.onlyInitOnceMap_[key]
				}
			}
		})
	}
})
// 复制到粘贴板功能
Vue.use(VueClipboard)

import "./assets/base.scss"
import "@/assets/style.scss"
import "./plugins/element.js"

Vue.config.productionTip = false

const initHandle = () => {
	window.g_instance = new Vue({
		router,
		store: store,
		render: (h) => h(App)
	}).$mount("#app")
	const actionTime = new Date().getTime()
	localStorage.setItem('actionTime', actionTime)
}

if (process.env.VUE_APP_MOCK === "true") {
	setTimeout(() => {
		initHandle()
	}, 2000)
} else {
	initHandle()
}

